<?php

namespace app\admin\controller;

class Student extends Base
{
    //学生教师列表
    public function student()
    {
        $student = model('common/Student') -> paginate(8);
        $data = [
            'student' => $student
        ];
        $this -> assign($data);
        return view();
    }
    //学生教师添加
    public function student_add()
    {
        if (request()->isAjax()){
            $data = input('post.');
            $data['photo'] = request()->file('myFile');
            $result = model('common/Student') -> student_add($data);
            if ($result == 1){
                $this -> success('添加成功！','admin/student/student');
            } else {
                $this -> error($result);
            }
        }
        return view();
    }
    //学生教师编辑
    public function student_edit()
    {
        if (request()->isAjax()){
            $data = input('post.');
            $data['photos'] = request()->file('myFile');
            $result = model('common/Student') -> student_edit($data);
            if ($result == 1){
                $this -> success('更新成功！','admin/student/student');
            } else {
                $this -> error($result);
            }
        }
        $student = model('common/Student') -> find(input('id'));
        $data = [
            'student' => $student
        ];
        $this -> assign($data);
        return view();
    }
    //学生教师删除
    public function student_del()
    {
        if (request()->isAjax()){
            $student = model('common/Student') -> find(input('post.'));
            $result = $student -> delete();
            if ($result){
                $this -> success('删除成功！','admin/student/student');
            } else {
                $this -> error($result);
            }
        }
    }
}
